<?php
include_once('common/header.php');
$strRefer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
if($AppUI->id <= 0 || $strRefer == '') {
	$arrJson 	= array('error'=>1,'msg'=>$arrError[1]);
	echo $objRequest->getParam('callback') . '(' . Zend_Json::encode($arrJson) . ')';
	exit();
}
$intAction 		= $objRequest->getParam('act',null);
$intBasketId 	= $objRequest->getParam('basketid',null);
$intProductId 	= $objRequest->getParam('productid',null);
$intError		= 0;
$objProduct 	= new Product();
$strMessage		= '';
$intQuantity	= 1;
$intTprice		= 0;
$intTargetId	= 0;
if(isset($intAction) && $intBasketId && $intProductId) {
	$arrInfo		= $objProduct->get($intProductId);
	$intDiscount	= $arrInfo['discount'];
	$intPrice		= $arrInfo['price'];
	/* if($intDiscount > 0) {
		$intPrice 	= $intPrice - (($intPrice*$intDiscount)/100); 
	} */
	if($intAction == 2) {
		$intQuantity = -1;
		$intPrice 	 = $intPrice * (-1);
	}
	$arrResult		= $objProduct->updateBasketQuantity($AppUI->id, $intBasketId, $intProductId, $intQuantity, $intPrice, $intTargetId);
	if($arrResult['errCode'] == 0) {
		$intQuantity	= isset($arrResult['quantity']) ? $arrResult['quantity'] : 0;
		$intTprice		= isset($arrResult['price']) ? $arrResult['price'] : 0;
	} else {
		$intError		= ($arrResult['errCode']) + 20; 
	}
	
} else {
	$intError		= 8;
}
if($intError == 0) {
	$arrBasketStat 	= $objProduct->getBasketSta($AppUI->id, $intTargetId);
	$arrJson		= array('error'	=> 0,						
						'quantity'	=> Vfriend_Function::numberFormat($intQuantity),
						'price'		=> Vfriend_Function::numberFormat($intTprice),
						'tprice'	=> Vfriend_Function::numberFormat(isset($arrBasketStat['tprice']) ? $arrBasketStat['tprice'] : 0)
						);
	echo $objRequest->getParam('callback') . '(' . Zend_Json::encode($arrJson) . ')';
	
} else {
	$arrJson 	= array('error'=>$intError,'msg'=>$arrError[$intError]);
	echo $objRequest->getParam('callback') . '(' . Zend_Json::encode($arrJson) . ')';
}
exit();
?>
